﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace TankWin.Classes
{
    class GUIPause:GUI
    {
        public const int _NUMBER = 4;
        public static bool _isPause;

        protected int _curItem = 0;
        static string[] _menuItem = new string[4]{
            "RESUME",
            "OPTION",
            "MENU",
            "QUIT"

        };
        public GUIPause() { }
        public override void Draw(Graphics _G)
        {
            _isPause = true;
            if (this._Graphics != _G)
                this._Graphics = _G;
            Bitmap _buffer = new Bitmap(300, 200);
            Graphics _gbuffer = Graphics.FromImage(_buffer);
            _gbuffer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            _gbuffer.Clear(Color.Black);

            Pen _pen = new Pen(Color.Silver, 10);
            _gbuffer.DrawRectangle(_pen, new Rectangle(0, 0, 300, 200));

            Font _font=new Font("Times New Roman",20,FontStyle.Bold);
            for(int i=0;i<_NUMBER;i++)
            {

                string _item=_menuItem[i];
                _gbuffer.DrawString(_item,_font,Brushes.Silver,new PointF(150-14*_item.Length/2,40+33*i));
                if(i==_curItem)
                {
                     _gbuffer.DrawString(_item,_font,Brushes.Red,new PointF(150-14*_item.Length/2,40+33*i));
                    _gbuffer.DrawString("O     ",_font,Brushes.Red,new PointF(150-14*"O     ".Length,40+33*i));

                }
               
            }
            _G.DrawImageUnscaled(_buffer,170,220);
        }
        public override void InputKey(Keys _key)
        {
            if (GUIMainMenu._move_player.IsLoadCompleted && GUIPlay._hasSound)
                GUIMainMenu._move_player.Play();
            switch (_key)
            {
                case Keys.Up:
                    _curItem += _NUMBER - 1;
                    _curItem %= _NUMBER;
                    break;
                case Keys.Down:
                    _curItem++;
                    _curItem %= _NUMBER;
                    break;
                case Keys.Left:
                    _curItem++;
                    _curItem %= _NUMBER;
                    break;
                case Keys.Right:
                    _curItem += _NUMBER - 1;
                    _curItem %= _NUMBER;
                    break;
                case Keys.Enter:
                    if (GUIMainMenu._enter_player.IsLoadCompleted && GUIPlay._hasSound)
                        GUIMainMenu._enter_player.Play();
                    if (_curItem == 0)//resume
                    {
                        _isPause = false;
                        frMain._statusGUI = EStatusGUI.PlayGUI;
                    }
                    if (_curItem == 1)//option
                    {
                        _isPause = false;
                        frMain._makeNewGame = false;
                        frMain._statusGUI = EStatusGUI.OptionGUI;
                        
                    }
                    if (_curItem == 2)//menu
                    {
                        _isPause = false;
                        frMain._makeNewGame = true;
                        frMain._statusGUI = EStatusGUI.MainMenuGUI;
                    }
                    if (_curItem == 3)//quit
                    {
                        _isPause = true;
                        frMain._statusGUI = EStatusGUI.ExitGUI;

                    }
                    break;


            }
        }
    }
}
